import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* Router Modules */

/** note: submenu only apppear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/authredirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'DASHBOARD', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    name: 'userManage',
    meta: { title: 'USER_MANAGE', icon: 'user' },
    children: [
      { path: '/user/list', component: () => import('@/views/user/list'), name: 'user', meta: { title: 'USER', icon: 'list' }},
      { path: '/address/list', component: () => import('@/views/address/list'), name: 'address', meta: { title: 'ADDRESS', icon: 'list' }},
      { path: '/collect/list', component: () => import('@/views/collect/list'), name: 'collect', meta: { title: 'COLLECT', icon: 'list' }},
      { path: '/history/list', component: () => import('@/views/history/list'), name: 'history', meta: { title: 'HISTORY', icon: 'list' }},
      { path: '/search/list', component: () => import('@/views/search/list'), name: 'search', meta: { title: 'SEARCH', icon: 'list' }}
    ]
  },

  {
    path: '/mall',
    component: Layout,
    redirect: '/brand',
    name: 'mallManage',
    meta: { title: 'MALL_MANAGE', icon: 'shoppingCard' },
    children: [
      { path: '/region', component: () => import('@/views/region/list'), name: 'region', meta: { title: 'REGION', icon: 'list' }},
      { path: '/brand', component: () => import('@/views/brand/list'), name: 'brand', meta: { title: 'BRAND', icon: 'list' }},
      { path: '/category', component: () => import('@/views/category/list'), name: 'category', meta: { title: 'CATEGORY', icon: 'list' }},
      { path: '/order', component: () => import('@/views/order/list'), name: 'order', meta: { title: 'ORDER', icon: 'list' }},
      { path: '/issue', component: () => import('@/views/issue/list'), name: 'issue', meta: { title: 'ISSUE', icon: 'list' }},
      { path: '/keyword', component: () => import('@/views/keyword/list'), name: 'keyword', meta: { title: 'KEYWORD', icon: 'list' }}
    ]
  },

  {
    path: '/product',
    component: Layout,
    redirect: '/product/list',
    name: 'productManage',
    meta: { title: 'PRODUCT_MANAGE', icon: 'component' },
    children: [
      { path: '/product/list', component: () => import('@/views/product/list'), name: 'product_list', meta: { title: 'PRODUCT_LIST', icon: 'list' }},
      { path: '/product/create', component: () => import('@/views/product/create'), name: 'create_product', meta: { title: 'CREATE_PRODUCT', icon: 'list' }},
      { path: '/product/edit', component: () => import('@/views/product/edit'), name: 'edit_product', meta: { title: 'EDIT_PRODUCT', icon: 'list' }},
      { path: '/product/comment', component: () => import('@/views/product/comment'), name: 'comment_product', meta: { title: 'COMMENT_PRODUCT', icon: 'list' }}
    ]
  },

  {
    path: '/address',
    component: Layout,
    redirect: '/address/list',
    name: 'promotionManage',
    meta: { title: 'PROMOTION_MANAGE', icon: 'guide' },
    children: [
      { path: '/ad', component: () => import('@/views/ad/list'), name: 'ad', meta: { title: 'AD', icon: 'list' }},
      { path: '/topic', component: () => import('@/views/topic/list'), name: 'topic', meta: { title: 'TOPIC', icon: 'list' }}
    ]
  },

  {
    path: '/address',
    component: Layout,
    redirect: '/address/list',
    name: 'systemManage',
    meta: { title: 'SYSTEM_MANAGE', icon: 'example' },
    children: [
      { path: '/admin/list', component: () => import('@/views/admin/list'), name: 'admin', meta: { title: 'ADMIN', icon: 'list' }},
      { path: '/os/list', component: () => import('@/views/os/list'), name: 'os', meta: { title: 'OS', icon: 'list' }}
    ]
  },

  {
    path: '/address',
    component: Layout,
    redirect: '/address/list',
    name: 'stat',
    meta: { title: 'STAT', icon: 'chart' },
    children: [
      { path: '/stat/user', component: () => import('@/views/stat/user'), name: 'statUser', meta: { title: 'STAT_USER', icon: 'list' }},
      { path: '/stat/order', component: () => import('@/views/stat/order'), name: 'statOrder', meta: { title: 'STAT_ORDER', icon: 'list' }},
      { path: '/stat/product', component: () => import('@/views/stat/product'), name: 'statProduct', meta: { title: 'STAT_PRODUCT', icon: 'list' }}
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]
